package com.cn.Spring.Dao;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public abstract class MyBatisUtil {
    public static SqlSessionFactory factory = null;
    public static SqlSessionFactory getSqlSessionFactory(){
//        InputStream config = MyBatisUtil.class.getClassLoader().getResourceAsStream("MyBatisCfg.xml");
        InputStream config = MyBatisUtil.class.getClassLoader().getResourceAsStream("WEB-INF/ApplicationContext.xml");
        factory = new SqlSessionFactoryBuilder().build(config);
        return factory;
    }

    public static SqlSession getSession(){
        return getSqlSessionFactory().openSession(true);
    }

    public static SqlSession getSession(boolean isAutoCommit){
        return getSqlSessionFactory().openSession(isAutoCommit);
    }
}


